package com.canaan.business.controller.pc.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.canaan.business.domain.basic.WmsCodeRule;
import com.canaan.business.domain.storehouse.StockCheck;
import com.canaan.business.domain.vo.WmsCodeRuleVo;
import com.canaan.business.service.basic.IWmsCodeRuleService;
import com.canaan.common.utils.TableNoUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 条码规则Controller
 *
 * @author ruoyi
 * @date 2023-01-29
 */
@Api(tags = "条码规则")
@RestController
@RequestMapping("/system/rule")
public class WmsCodeRuleController extends BaseController {
    @Autowired
    private IWmsCodeRuleService wmsCodeRuleService;

    /**
     * 查询条码规则列表
     */
    @ApiOperation(value = "查询条码规则列表")
    @GetMapping("/list")
    public TableDataInfo list(WmsCodeRule wmsCodeRule) {
        startPage();
        List<WmsCodeRule> list = wmsCodeRuleService.selectWmsCodeRuleList(wmsCodeRule);
        return getDataTable(list);
    }

    /**
     * 导出条码规则列表
     */
    @ApiOperation(value = "导出条码规则列表")
    @Log(title = "条码规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsCodeRule wmsCodeRule) {
        List<WmsCodeRule> list = wmsCodeRuleService.selectWmsCodeRuleList(wmsCodeRule);
        ExcelUtil<WmsCodeRule> util = new ExcelUtil<WmsCodeRule>(WmsCodeRule.class);
        util.exportExcel(response, list, "条码规则数据");
    }

    /**
     * 获取条码规则详细信息
     */
    @ApiOperation(value = "获取条码规则详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wmsCodeRuleService.selectWmsCodeRuleById(id));
    }

    /**
     * 新增条码规则
     */
    @ApiOperation(value = "新增条码规则")
    @Log(title = "条码规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsCodeRule wmsCodeRule) {
        return toAjax(wmsCodeRuleService.insertWmsCodeRule(wmsCodeRule));
    }

    /**
     * 修改条码规则
     */
    @ApiOperation(value = "修改条码规则")
    @Log(title = "条码规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsCodeRule wmsCodeRule) {
        return toAjax(wmsCodeRuleService.updateWmsCodeRule(wmsCodeRule));
    }

    /**
     * 删除条码规则
     */
    @ApiOperation(value = "删除条码规则")
    @Log(title = "条码规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wmsCodeRuleService.deleteWmsCodeRuleByIds(ids));
    }

    /**
     * 新增更新条码规则及明细
     */
    @ApiOperation(value = "新增更新条码规则及明细")
    @Log(title = "新增更新条码规则及明细", businessType = BusinessType.INSERT)
    @PostMapping("/addAndUpdateDetail")
    public AjaxResult addAndUpdateDetail(@RequestBody WmsCodeRuleVo wmsCodeRuleVo) {
        return toAjax(wmsCodeRuleService.addAndUpdateDetail(wmsCodeRuleVo));
    }

    /**
     * 获取条码规则详细信息
     */
    @ApiOperation(value = "获取条码规则详细信息")
    @GetMapping(value = "/getWithDetail/{id}")
    public AjaxResult getWithDetail(@PathVariable("id") Long id) {
        return success(wmsCodeRuleService.getWithDetail(id));
    }


    /**
     * test
     */
    @ApiOperation(value = "test")
    @GetMapping(value = "/test")
    public AjaxResult test(@RequestParam("tableName")String tableName) {
        String wms_stock_check = TableNoUtil.getNo(StockCheck.class);
        return success(wms_stock_check);
    }

}
